package com.kadron.users;

import java.io.Serializable;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.common.KConst;
import com.kadron.dao.KUserDAO;
import com.kadron.dao.KUserImageDAO;
import com.kadron.dao.KUserKadronsDAO;
import com.kadron.entity.User;
import com.kadron.entity.UserImage;
import com.kadron.manager.KSelection;

@AutoCreate
@Name("kUserManager")
@Scope(ScopeType.PAGE)
public class KUserManager extends AbstractUserManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4961646080546501375L;

	private User user; 
	private UserImage img;
	private Long kadrons;
	
	@In
	private KUserDAO userDAO;
	@In
	private KUserKadronsDAO userKadronsDAO;
	@In
	private KUserImageDAO userImageDAO;
	
	@Create
	public void init() {
		Long userId = (Long) Component.getInstance("userId");
		if (userId == null || userId <= 0) {
			setError(true);
			return;
		}
		kadrons = userKadronsDAO.getUserKadrons(userId);
		user = (User) userDAO.find(userId, User.class);
		img = userImageDAO.findByUser(userId);
	}
	
	public String orders() {
		if (user == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		KSelection kselection = (KSelection) Component.getInstance("kSelection");
		kselection.setItemId(user.getId());
		return "e_user_order";
	}
	
	public User getUser() {
		return user;
	}

	public UserImage getImg() {
		return img;
	}

	public Long getKadrons() {
		return kadrons;
	}
	
}